export default {
  validateInternationalPhoneNumber(phoneNumber) {
    const pattern = /^1[3-9]\d{9}$/;

    // 使用正则表达式测试手机号码
    if (pattern.test(phoneNumber)) {
      return true;
    } else {
      return false;
    }
  },
  formatDate(cellValue) {
    console.log(cellValue, 'cellValue')
    if (cellValue == null || cellValue == "") return "";
    var date = new Date(cellValue)
    var year = date.getFullYear()
    var month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
    var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
    var hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
    var minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
    var seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
    return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds
  },
  formatTime(date) {
    let y = date.getFullYear();
    let m = this.padZero(date.getMonth() + 1);
    let d = this.padZero(date.getDate());
    let hh = this.padZero(date.getHours());
    let mm = this.padZero(date.getMinutes());
    let ss = this.padZero(date.getSeconds());
    return `${y}-${m}-${d}`;
  },
  padZero(num) {
    return num < 10 ? '0' + num : num;
  },
  timestampToDateString(timestamp) {
    const date = new Date(timestamp); // 时间戳通常是以秒为单位，需要乘以1000转换为毫秒
    const year = date.getFullYear();
    const month = String(date.getMonth() + 1).padStart(2, '0'); // getMonth() 返回的是0-11，需要加1
    const day = String(date.getDate()).padStart(2, '0');
    return `${year}-${month}-${day}`;
  },
};
